<template>
  <el-dialog
    title="新增评价"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="1200px"
    append-to-body
  >
    <el-row class="JADP-common-search-box" :gutter="16">
      <el-form @submit.native.prevent>
        <!-- <el-col :span="6">
          <el-form-item label="评价分类">
            <el-select v-model="query.categore" placeholder="请选择" clearable>
              <el-option
                v-for="(item, index) in getDict('pingjiafeilei')"
                :key="index"
                :label="item.dataName"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="6">
          <el-form-item label="评价项目">
            <el-input v-model="query.name" placeholder="请输入" clearable>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search()"
              >查询</el-button
            >
            <el-button icon="el-icon-refresh-right" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" :selectable="selectEvent">
      </el-table-column>
      <el-table-column type="index" width="50" label="序号"> </el-table-column>
      <el-table-column prop="categore" label="评价分类" align="left" />
      <el-table-column prop="name" label="评价项目" align="left" />
      <el-table-column prop="creatoruserid" label="创建用户" align="left" />
      <el-table-column prop="creatortime" label="创建时间" align="left" />
    </el-table>
    <pagination
      :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      @pagination="init"
    />
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
export default {
  name: "evaluationForm",
  props: {
    manageid: {
      type: String,
      default: ""
    },
    categore: {
      type: [String, Number],
      default: "0"
    },
    parentList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      list: [],
      listLoading: false,
      total: 0,
      visible: false,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "categore"
      },
      multipleSelection: [],
      query: {
        name: undefined
      }
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    init() {
      this.visible = true;
      this.listLoading = true;
      this.query.categore = this.categore;
      let _query = {
        ...this.listQuery,
        ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/xy_pj_base/Xy_pj_base`,
        method: "get",
        data: query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.listLoading = false;
      });
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    dataFormSubmit() {
      if (!this.multipleSelection.length) {
        this.$message({
          message: "请选择评价项目",
          type: "warning"
        });
        return;
      }
      let list = this.multipleSelection.map(item => {
        return {
          name: item.name,
          manageid: this.manageid
        };
      });
      request({
        url: "/api/xy_pj_manage_score/Xy_pj_manage_score",
        method: "post",
        data: {
          manageScoreCrForms: list,
          organizeId :this.$store.getters.organizeId
        }
      }).then(res => {
        this.$message({
          message: res.msg,
          type: "success"
        });
        this.visible = false;
        this.$emit("submit");
      });
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "categore"
      };
      this.init();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "categore"
      };
      this.init();
    },
    selectEvent(row) {
      let flag = true;
      this.parentList.forEach(item => {
        if (item.name == row.name) {
          flag = false;
        }
      });
      return flag;
    }
  }
};
</script>

<style scoped lang="scss"></style>
